package com.ddd.demo.controller;

import com.ddd.demo.domain.eo.User;
import com.ddd.demo.service.UserService;
import com.ddd.demo.util.config.Payload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping(value = "/api/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * @param id
     * @return
     */
    @RequestMapping(value = "/findUserById",method = RequestMethod.GET)
    @ResponseBody
    public Payload findUserById(int id){
        return new Payload(userService.findById(id));
    }

    /**
     * page demo
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/findUserPage",method = RequestMethod.GET)
    @ResponseBody
    public Payload<PageInfo<User>> findUserPage(int page, int pageSize){
        return new Payload<>(userService.findUserPage(page,pageSize));
    }

    /**
     * batch demo
     */
    @RequestMapping(value = "/insertBatch",method = RequestMethod.GET)
    @ResponseBody
    public Payload insertBatch(){
        userService.insertBatch();
        return new Payload();
    }
}
